'''
Author: Donald duck tang5722917@163.com
Date: 2024-04-15 19:46:07
LastEditors: Donald duck tang5722917@163.com
LastEditTime: 2024-04-18 11:46:21
FilePath: \spice_netlist_front_end\src\Anasysis\Matrix\matrix_fac.py
Description: 
Copyright (c) 2024 by Donald duck email: tang5722917@163.com, All Rights Reserved.
'''
from Circuit_element import Element_2port

def build_matrix(opt,elem_obj_list,node_obj_list) :
    m =list()
    node_list = list()
    elem_list = list()
    node_list_name = list()
    elem_list_name = list()
    A=list()
    row = list()
    for line in node_obj_list:
        if(line.leng_elem() == 0):
            continue
        print(line.print_node())
        for elem in elem_obj_list:
            if(isinstance(elem, Element_2port.Element_2port)):
                if (line.eq_name(elem.return_neg_node().print_node_name())):
                    row.append(1)
                elif (line.eq_name(elem.return_pos_node().print_node_name() )):
                    row.append(-1)
                else:
                    row.append(0)
        A.append(row.copy())
        row.clear()
        node_list.append(line)
        node_list_name.append(line.print_node_name())
    for elem in elem_obj_list:
        elem_list.append(elem)
        elem_list_name.append(elem.print_elem_name())
    print(A)
    A = A[1:]
    print(node_list_name)
    print(elem_list_name)
    return m
